﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zzva.Common;


namespace Zzva.DomainObject
{
    public class TDirSoftware: TDirSoftwareBase 
    {

        private TEsbDomainObject mvarEsbDomainObject;
        private int mvarId;
        private int mvarHolderId;
        private int mvarDeveloperId;


        ////
        private int mvarSoftTypeId;



        public override TDirSoftTypeBase SoftType
        {
            get
            {
                try
                {
                    if (mvarSoftType == null)
                    {
                        if (mvarSoftTypeId == 0)
                        { mvarSoftType = new TDirSoftTypeNull(); }
                        else
                        { mvarSoftType = Esb.GetSoftType(mvarSoftTypeId); }
                    }

                    return mvarSoftType;
                }
                catch (Exception e) { throw e; }
                finally { }
            }

            set
            {
                try
                {
                    Type lTypeObject;
                    lTypeObject = value.GetType();

                    switch (lTypeObject.Name)
                    {
                        case "TDirSoftTypeNew": throw (new CommonException("Ссылка должна быть на постоянный или нулевой объект"));
                        case "TDirSoftType":
                        case "TDirSoftTypeNull":
                            mvarSoftType = value;
                            break;
                        default: throw (new CommonException("Не существует объекта"));
                    }
                }
                catch (Exception e) { throw e; }
                finally { }
            }

        }



        ////
        public TDirSoftware(TEsbDomainObject EsbDomainObject,
            int pId, string pObozn, string pNaim, int pHolderId, int pDeveloperId,
            int pSoftTypeId)
            : base()
        {
            mvarEsbDomainObject = EsbDomainObject;
            mvarId = pId;
            mvarObozn = pObozn;
            mvarNaim = pNaim;
            mvarHolderId = pHolderId;
            mvarDeveloperId = pDeveloperId;

            mvarSoftTypeId = pSoftTypeId;
        }

































































































































        public override string Obozn
        {
            get { return mvarObozn; }



            //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            //На время первоночального заполнения справочника
            ////set { if (mvarObozn != value) { throw (new CommonException("Обозначение нельзя изменять")); } }
            set { mvarObozn = value; }      
        
        
        
        
        }


















        public TDirSoftware(TEsbDomainObject EsbDomainObject,
            int pId, string pObozn, string pNaim, int pHolderId, int pDeveloperId)
            : base()

        {
            mvarEsbDomainObject = EsbDomainObject;
            mvarId = pId;
            mvarObozn = pObozn;
            mvarNaim = pNaim;
            mvarHolderId = pHolderId;
            mvarDeveloperId = pDeveloperId;
        }








        public override  int Id
        {
            get { return mvarId; }
        }




        private TEsbDomainObject Esb
        {
            get
            {
                try
                {
                    return mvarEsbDomainObject;
                }
                catch (Exception e) { throw e; }
                finally { }
            }
        }


        public override string Naim
        {
            get{return mvarNaim;}
            set{mvarNaim = value;}
        }

        public override TDirITCompanyBase Developer
        {
            get
            {
                try
                {
                    if (mvarDeveloper == null)
                    {
                        if (mvarDeveloperId == 0)
                        { mvarDeveloper = new TDirITCompanyNull(); }
                        else
                        { mvarDeveloper = Esb.GetITCompany(mvarDeveloperId );}
                    }

                    return mvarDeveloper;
                }
                catch (Exception e) { throw e; }
                finally { }
            }

            set
            {
                try
                {
                    Type lTypeObject;
                    lTypeObject = value.GetType();

                    switch (lTypeObject.Name)
                    {
                        case "TDirITCompanyNew": throw (new CommonException("Ссылка должна быть на постоянный или нулевой объект"));
                        case "TDirITCompany":
                        case "TDirITCompanyNull":
                            mvarDeveloper = value;
                            break;
                        default: throw (new CommonException("Не существует объекта"));
                    }
                }
                catch (Exception e) { throw e; }
                finally { }
            }

        }


        public override TDirITCompanyBase Holder
        {
            get
            {
                try
                {
                    if (mvarHolder == null)
                    {
                        if (mvarHolderId == 0)
                        { mvarHolder = new TDirITCompanyNull() ; }
                        else
                        { mvarHolder = Esb.GetITCompany(mvarHolderId); }
                    }
                    return mvarHolder;
                }
                catch (Exception e) { throw e; }
                finally { }
            }

            set
            {
                try
                {
                    Type lTypeObject;
                    lTypeObject = value.GetType();

                    switch (lTypeObject.Name)
                    {
                        case "TDirITCompanyNew": throw (new CommonException("Ссылка должна быть на постоянный или нулевой объект"));
                        case "TDirITCompany":
                        case "TDirITCompanyNull":
                            mvarHolder = value;
                            break;
                        default: throw (new CommonException("Не существует объекта"));
                    }

                }
                catch (Exception e) { throw e; }
                finally { }
            }
        }


    }
}
